home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 116_01.zip / ADVENT.C < prev    next >
Text File  |  1993-06-19  |  5KB  |  231 lines

  1.  
  2. /*  program ADVENT.C    modified by LCC for V 1.43 by:
  3.     altering buffer sizes
  4. */
  5. #include "advent.h"
  6.  
  7. main(argc,argv)
  8. char **argv;
  9. {
  10.     int rflag;            /* user restore request option */
  11.  
  12.     rflag = 0;
  13.     while (--argc > 0) {
  14.         ++argv;
  15.         if (**argv != '-')
  16.             break;
  17.         switch(tolower(argv[0][1])) {
  18.         case 'r':
  19.             ++rflag;
  20.             continue;
  21.         case 'd':
  22.             ++dbgflg;
  23.             continue;
  24.         default:
  25.             printf("unknown flag: %c\n",argv[0][1]);
  26.             continue;
  27.         }
  28.     }
  29.     init();
  30.     if (rflag)
  31.         restore();
  32.     exec("eadvent");
  33. }
  34.  
  35. /*
  36.     Initialization
  37. */
  38. init()
  39. {
  40.     int c;
  41.     int i,j,offset;
  42.     char *wptr, *wordptr;
  43.     char word[WORDSIZE];
  44.     int wval;
  45.  
  46.     turns=0;
  47.  
  48.     /* initialize location status array */
  49.     setmem(cond,MAXLOC,0);
  50.     initb(cond,"0,5,1,5,5,1,1,5,17,1,1");
  51.     initb(&cond[11],"0,0,32,0,0,2,0,0,64,2");
  52.     initb(&cond[21],"2,2,0,6,0,2,0,0,0,0");
  53.     initb(&cond[31],"2,2,0,0,0,0,0,4,0,2");
  54.     initb(&cond[41],"0,128,128,128,128,136,136,136,128,128");
  55.     initb(&cond[51],"128,128,136,128,136,0,8,0,2");
  56.     initb(&cond[80],"128,128,136,0,0,8,136,128,0,2,2");
  57.     initb(&cond[91],"0,0,0,0,4,0,0,0,0,1");
  58.     initb(&cond[111],"0,0,4,0,1,1,0,0,0,0");
  59.     initb(&cond[121],"0,8,8,8,8,8,8,8,8,8");
  60.     cond[79]=2;
  61.  
  62.     /* initialize object locations */
  63.     setmem(place,2*MAXOBJ,0);
  64.     initw(&place[1],"3,3,8,10,11,0,14,13,94,96");
  65.     initw(&place[11],"19,17,101,103,0,106,0,0,3,3");
  66.     initw(&place[21],"0,0,109,25,23,111,35,0,97,0");
  67.     initw(&place[31],"119,117,117,0,130,0,126,140,0,96");
  68.     initw(&place[50],"18,27,28,29,30,0,92,95,97,100,101,0,119,127,130");
  69.  
  70.     /* initialize second (fixed) locations */
  71.     setmem(fixed,2*MAXOBJ,0);
  72.     initw(&fixed[1],"0,0,9,0,0,0,15,0,-1");
  73.     initw(&fixed[11],"-1,27,-1,0,0,0,-1");
  74.     initw(&fixed[21],"0,0,-1,-1,67,-1,110,0,-1,-1");
  75.     initw(&fixed[31],"121,122,122,0,-1,-1,-1,-1,0,-1");
  76.     fixed[62]=121;
  77.     fixed[64]=-1;
  78.  
  79.     /* initialize default verb messages */
  80.     initb(actmsg,"0,24,29,0,33,0,33,38,38,42,14");
  81.     initb(&actmsg[11],"43,110,29,110,73,75,29,13,59,59");
  82.     initb(&actmsg[21],"174,109,67,13,147,155,195,146,110,13,13");
  83.  
  84.     /* initialize various flags and other variables */
  85.     setmem(visited,MAXLOC,0);
  86.     setmem(prop,2*MAXOBJ,0);
  87.     setmem(&prop[50],2*(MAXOBJ-50),0xff);
  88.     wzdark=closed=closing=holding=detail=0;
  89.     limit=100;
  90.     tally=15;
  91.     tally2=0;
  92.     newloc=3;
  93.     loc=oldloc=oldloc2=1;
  94.     knfloc=0;
  95.     chloc=114;
  96.     chloc2=140;
  97.     initw(dloc,"0,19,27,33,44,64");
  98.     initw(odloc,"0,0,0,0,0,0,0");
  99.     dloc[DWARFMAX-1]=chloc;
  100.     dkill=0;
  101.     initb(dseen,"0,0,0,0,0,0,0");
  102.     clock=30;
  103.     clock2=50;
  104.     panic=0;
  105.     bonus = 0;
  106.     numdie = 0;
  107.     daltloc = 18;
  108.     lmwarn = 0;
  109.     foobar = 0;
  110.     dflag = 0;
  111.     gaveup = 0;
  112.     saveflg = 0;
  113.     dbgflg = 0;
  114.     printf("Go read a book while I get my act together...\n");
  115.     /*
  116.        initialize disk index arrays
  117.     */
  118.     for(i=0;i<MAXLOC/10;++i)
  119.         idx1[i]=idx2[i]=idx3[i]=0;
  120.     for(i=0;i<30;++i)
  121.         idx6[i]=0;
  122.     fd[1]=fopen("advent1.dat",dbuff);
  123.     fd[2]=fopen("advent2.dat",dbuff);
  124.     fd[3]=fopen("advent3.dat",dbuff);
  125.     fd[4]=fopen("advent4.dat",dbuff);
  126.     fd[6]=fopen("advent6.dat",dbuff);
  127.     for(i=1;i<=3;++i) {
  128.         swchfd(i);
  129.         if(fseek(dbuff,0,0)==-1)
  130.             bug(42);
  131.         offset=0;
  132.         for(j=0;j<141;++j) {
  133.             while((c=getc(dbuff))!='#') {
  134.                 if(c==-1 || c==EOF)
  135.                     bug(40);
  136.                 ++offset;
  137.             }
  138.             if(j%10 == 0) {
  139.                 switch(i) {
  140.                 case 1:
  141.                     idx1[j/10]=offset;
  142.                     break;
  143.                 case 2:
  144.                     idx2[j/10]=offset;
  145.                     break;
  146.                 case 3:
  147.                     idx3[j/10]=offset;
  148.                     break;
  149.                 default:
  150.                     break;
  151.                 }
  152.             }
  153.         ++offset;
  154.         }
  155.     }
  156.     offset=0;
  157.     swchfd(6);
  158.     if(fseek(dbuff,0,0)==-1)
  159.         bug(43);
  160.     for(j=0;j<201;++j) {
  161.         while((c=getc(dbuff))!='#') {
  162.             if(c==-1 || c==EOF)
  163.                 bug(41);
  164.             ++offset;
  165.         }
  166.         if(j%10 == 0) {
  167.             idx6[j/10]=offset;
  168.         }
  169.         ++offset;
  170.     }
  171.     /*
  172.         initialize fast verb arrays
  173.     */
  174.     swchfd(4);
  175.     if (fseek(dbuff,0,0) == -1)
  176.         bug(46);
  177.     fastvseek = 0;
  178.     wptr = fastverb;
  179.     wval = 0;
  180.     while(wptr < &fastverb[MAXVFAST-WORDSIZE] &&
  181.           wval < MAXVVAL) {
  182.         while((c=getc(dbuff)) != ',') {
  183.             if (c == -1 || c == EOF)
  184.                 bug(44);
  185.             ++fastvseek;
  186.             *wptr++ = c;
  187.         }
  188.         ++fastvseek;
  189.         *wptr++ = 0;
  190.         wordptr = word;
  191.         while((c=getc(dbuff)) != '\n') {
  192.             if (c == -1 || c == EOF)
  193.                 bug(45);
  194.             ++fastvseek;
  195.             *wordptr++ = c;
  196.         }
  197.         ++fastvseek;
  198.         *wordptr++ = 0;
  199.         fastvval[wval++] = atoi(word);
  200.     }
  201.  }
  202.  
  203. /*
  204.     restore saved game handler
  205. */
  206. restore()
  207. {
  208.     char username[13];
  209.     int restfd,c;
  210.     char *sptr;
  211.  
  212.     printf("What is your saved game name? ");
  213.     scanf("%s",username);
  214.     strcat(username,".adv");
  215.     if ((restfd=fopen(username,dbuff)) == -1) {
  216.         printf("sorry, can''t open save file...\n");
  217.         exit();
  218.     }
  219.     for (sptr=&turns; sptr<&lastglobal; sptr++) {
  220.         if ((c=getc(dbuff)) == -1) {
  221.             printf("can''t read save file...\n");
  222.             exit();
  223.         }
  224.         *sptr = c;
  225.     }
  226.     if (close(restfd) == -1) {
  227.         printf("warning -- can''t close save file...\n");
  228.     }
  229.     saveflg = 0;
  230. }
  231.